<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        ul li{
            width: 400px;
            height: 400px;
            background-color: #aaa;
            margin: 0 auto;
            margin-bottom: 600px;
        }
        .brdsd{
            width: 100px;
            height: 120px;
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
        }
        .brdsd div{
            width: 100px;
            height: 29px;
            background-color: aqua;
            border-bottom: 1px solid #aaa;
            text-align: center;
            line-height: 29px;
            cursor: pointer;
            transition: all 0.5s;
        }
        .brdsd div:hover{
            background-color: pink;
            transform: scale(1.5);
        }
    </style>
</head>
<body>
    <ul>
        <li>楼层1</li>
        <li>楼层2</li>
        <li>楼层3</li>
        <li>楼层4</li>
    </ul>
    <div class="brdsd">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
    </div>
    <script>
        //需求：点击侧边的栏滚动到对应的地方
        let divs=document.querySelectorAll(".brdsd div")
        let lis=document.querySelectorAll("ul li")
        let timeId=null
        divs.forEach((i,j) => {
            i.addEventListener("click",function(){
                if (timeId) {
                    return
                }
                if (document.documentElement.scrollTop>=lis[j].offsetTop) {
                    timeId=setInterval(() => {
                        document.documentElement.scrollTop=document.documentElement.scrollTop-20
                        if (document.documentElement.scrollTop<=lis[j].offsetTop) {
                            clearInterval(timeId)
                            timeId=null
                        }
                    }, 20);
                }else{
                    timeId=setInterval(() => {
                        document.documentElement.scrollTop=document.documentElement.scrollTop+20
                        if (document.documentElement.scrollTop>=lis[j].offsetTop) {
                            clearInterval(timeId)
                            timeId=null
                        }
                    }, 20);
                }
            })
        });
    </script>
</body>
</html>